import 'package:word_game/engine/core.dart';

class Box extends Thing with Openable {
  String thingCode;
  Box(Map map) : super(map) {
    this.thingCode = map['thingCode'];
    this.add(OpenEvent());
  }

  @override
  Box.copy(Box obj): super.copy(obj) {
    this.code = obj.code;
    this.name = obj.name;
    this.thingCode = obj.thingCode;
  }

  @override
  Box copy() {
    Box box = super.copy();
    return box;
  }

  @override
  bool open() {
    if (this.thingCode == null || this.thingCode == '') {
      Engine.instance.displayer.displayString('${name}空空如也');
      return true;
    } else {
      Thing thing = MaterialManager.instance.newMaterialWithCode(this.thingCode);
      World.instance.hero.getThing(thing);
      return true;
    }
  }
}